package com.sourcetrip.my.abs;

import com.sourcetrip.my.inter.Map;
import com.sourcetrip.my.modle.RedBlackNode4Map;

/**
 * @author: ZhouBert
 * @date: 2020/12/24
 * @description:
 */
public abstract class AbstractMap<K,V> implements Map<K,V> {

	protected int size;
	protected RedBlackNode4Map<K, V> root = null;

	@Override
	public int size() {
		return size;
	}

	@Override
	public boolean isEmpty() {
		return size == 0;
	}

	@Override
	public void clear() {
		root = null;
		size = 0;
	}


	//region	BinaryTreeInfo 的接口

	@Override
	public Object root() {
		return root;
	}

	@Override
	public Object left(Object node) {
		return ((RedBlackNode4Map<K, V>) node).left;
	}

	@Override
	public Object right(Object node) {
		return ((RedBlackNode4Map<K, V>) node).right;
	}

	@Override
	public Object string(Object node) {
		return ((RedBlackNode4Map<K, V>) node).toString();
	}

	//endregion
}
